package util;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.ServletContext;
/**
 * Application Lifecycle Listener implementation class LoginListener
 *
 */
// ������ʵ�ּ�����¼����
@WebListener
public class LoginListener implements HttpSessionAttributeListener {
	private int num;
    /**
     * Default constructor. 
     */
    public LoginListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)
     */
    public void attributeAdded(HttpSessionBindingEvent se)  { 
         // TODO Auto-generated method stub
    	ServletContext context = se.getSession().getServletContext();
    	if ("loginUser".equals(se.getName())){
			num++;
			context.setAttribute("loginUserNum", num);
		}
    }

	/**
     * @see HttpSessionAttributeListener#attributeRemoved(HttpSessionBindingEvent)
     */
    public void attributeRemoved(HttpSessionBindingEvent se)  { 
         // TODO Auto-generated method stub
    	ServletContext context = se.getSession().getServletContext();
    	if ("loginUser".equals(se.getName())){
			num--;
			context.setAttribute("loginUserNum", num);
		}
    }

	/**
     * @see HttpSessionAttributeListener#attributeReplaced(HttpSessionBindingEvent)
     */
    public void attributeReplaced(HttpSessionBindingEvent se)  { 
         // TODO Auto-generated method stub
    }
	
}
